<html>
  <head>
    <title>Histogram</title>
    <script type="text/javascript" src="../../protovis.js"></script>
  </head>
  <body>
    <script type="text/javascript+protovis">

/* Generate an Irwin-Hall distribution. */
var n = 10000, // number of trials
    m = 10, // number of random variables
    data = pv.range(n).map(function() pv.sum(pv.range(m), Math.random));

var w = 300,
    h = 300,
    x = pv.Scale.linear(0, m).range(0, w),
    bins = pv.histogram(data).bins(x.ticks(20)),
    y = pv.Scale.linear(0, pv.max(bins, function(d) d.y)).range(0, h);

var vis = new pv.Panel()
    .width(w)
    .height(h)
    .margin(29.5)
    .top(14.5);

vis.add(pv.Bar)
    .data(bins)
    .left(function(d) x(d.x))
    .bottom(0)
    .width(function(d) x(d.dx))
    .height(function(d) y(d.y))
    .fillStyle("#aaa");

vis.add(pv.Rule)
    .data(x.ticks())
    .left(x)
    .bottom(-5)
    .height(5)
  .anchor("bottom").add(pv.Label)
    .text(function(d) x.tickFormat(d));

vis.add(pv.Rule)
    .data(y.ticks())
    .bottom(y)
    .strokeStyle("#fff")
  .anchor("left").add(pv.Label)
    .text(function(d) y.tickFormat(d));

vis.add(pv.Rule)
    .bottom(0);

vis.render();

    </script>
  </body>
</html>
